package com.macro.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fly.mapper.${modelNameUpperCamel}Mapper;
import com.fly.entity.${modelNameUpperCamel};
import com.fly.service.${modelNameUpperCamel}Service;
import org.springframework.stereotype.Service;

import java.util.List;
import javax.annotation.Resource;

/**
 * ${remarks}接口实现
 *
 * @author ${author}
 * @date ${date}
 */
@Service
public class ${modelNameUpperCamel}ServiceImpl extends ServiceImpl<${modelNameUpperCamel}Mapper, ${modelNameUpperCamel}>  implements ${modelNameUpperCamel}Service {

    @Resource
    private ${modelNameUpperCamel}Mapper ${modelNameLowerCamel}Mapper;

    @Override
    public Boolean create(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        int count = ${modelNameLowerCamel}Mapper.insert(${modelNameLowerCamel});
       return count <= 0;
    }

    @Override
    public Boolean deleteById(Long id) {
        int count = ${modelNameLowerCamel}Mapper.deleteById(id);
        return count <= 0;
    }

    @Override
    public Boolean batchDeleteByIds(List<Long> ids) {
        int count = ${modelNameLowerCamel}Mapper.deleteBatchIds(ids);
        return count <= 0;
    }

    @Override
    public Boolean update(Long id, ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}.setId(id);
        int count = ${modelNameLowerCamel}Mapper.updateById(${modelNameLowerCamel});
        return count <= 0;
    }

    @Override
    public Page<${modelNameUpperCamel}> fetchList(Integer pageNum, Integer pageSize, ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        QueryWrapper<${modelNameUpperCamel}> wrapper = new QueryWrapper<>(${modelNameLowerCamel});
        wrapper.orderByDesc("create_time");
        return ${modelNameLowerCamel}Mapper.selectPage(new Page<>(pageNum, pageSize), wrapper));
    }

    @Override
    public ${modelNameUpperCamel} fetchDetail(Long id) {
        return ${modelNameLowerCamel}Mapper.selectById(id);
    }
}
